package com.action.upload;

import java.io.File;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.entity.album.Album;
import com.entity.other.ShareType;
import com.service.album.AlbumService;
import com.util.abstractAction.AbstractAction;

public class ImageUploadAction extends AbstractAction {

    private static final long serialVersionUID = 4507801942660929013L;
    
    @Autowired
    private AlbumService albumService;

    //上传图片的数量 ，0为无线上传、1为上传一张、2为上传2张，依次类推
    private int number;

    //上传图片列表
    private File[] images;

    //上传图片名字列表
    private String[] imagesFileName;

    //返回图片地址列表（存入数据库）
    private String[] imageURLList;

    //上传是否成功   TRUE为成功  FALSE为失败
    private boolean flag;

    //操作类型，1为添加，2为修改，3为删除
    private int doType;

    //上传图片类型  city、food、hotel、scenic
    private String type;

    //预览位置,要在那里预览
    private String pos;
    
    private List<Album> albumList;
    
    private List<ShareType> shareTypeList;

    public String goImageUpload() {
    	try {
    		albumList=albumService.getAllAlbum();
    		shareTypeList=albumService.getAllShareType();
		} catch (Exception e) {
			e.printStackTrace();
		}
        return "go";
    }

    public String imageUpload() {
        int size = images.length;
        String path = "album/";
        imageURLList = new String[size];
        try {
            for (int i = 0; i < size; i++) {
                imageURLList[i] = saveImageFile(images[i], path, imagesFileName[i], 0, 0);
            }
            flag = true;
            return "upload";
        } catch (Exception e) { 
            return "";
        }

    }

    //内部方法  选取存放路径
    private String choosePath(String path) {
        
        if(type.equals("album")){
            path = "album/";
        }
        return path;
    }

    /********************************************************/
    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public String[] getImageURLList() {
        return imageURLList;
    }

    public void setImageURLList(String[] imageURLList) {
        this.imageURLList = imageURLList;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public File[] getImages() {
        return images;
    }

    public void setImages(File[] images) {
        this.images = images;
    }

    public String[] getImagesFileName() {
        return imagesFileName;
    }

    public void setImagesFileName(String[] imagesFileName) {
        this.imagesFileName = imagesFileName;
    }

    public String getType() {
        return type;
    }

    public int getDoType() {
        return doType;
    }

    public void setDoType(int doType) {
        this.doType = doType;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getPos() {
        return pos;
    }

    public void setPos(String pos) {
        this.pos = pos;
    }

	public List<Album> getAlbumList() {
		return albumList;
	}

	public void setAlbumList(List<Album> albumList) {
		this.albumList = albumList;
	}

	public List<ShareType> getShareTypeList() {
		return shareTypeList;
	}

	public void setShareTypeList(List<ShareType> shareTypeList) {
		this.shareTypeList = shareTypeList;
	}

    
}
